﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mirage;
using iTunesLib;
using System.Xml.Linq;
using System.Xml;
using System.Collections;
namespace MirageTest
{
    class Program
    {
        static void Main(string[] args)
        {
            iTunesApp itunes = new iTunesAppClass();
            IITTrackCollection tracks = itunes.LibraryPlaylist.Tracks;
            //XDocument itunesxml = XDocument.Load(itunes.LibraryXMLPath);
            //XmlTextReader xtr = (new XmlTextReader((itunes.LibraryXMLPath)));
            //xtr.readtt();
            Dictionary<string, object> itunesdic = new Dictionary<string, object>();//iTunesUtil.readDictionary(xtr);
            Db db = new Db();
            using (XmlTextReader reader = new XmlTextReader((itunes.LibraryXMLPath)))
            {
                // Skip to <plist>.
                while (reader.Read() && (
                    reader.NodeType != XmlNodeType.Element ||
                    reader.Name != "plist"))
                {
                    string s = reader.Name;
                }

                // Skip to <dict>.
                while (reader.Read() && (
                    reader.NodeType != XmlNodeType.Element ||
                    reader.Name != "dict"))
                {
                    string s = reader.Name;
                }
                while (reader.Read() && (
                   reader.NodeType != XmlNodeType.Element ||
                   reader.Name != "dict"))
                {
                    string s = reader.Name;
                }

                // Create and populate the dictinary.
                itunesdic = iTunesUtil.readDictionary(reader);
            }

            foreach (IITTrack track in tracks)
            {
                
                Console.WriteLine("Analyzing: " +((Dictionary<string, object>)itunesdic[track.TrackDatabaseID.ToString()])["Location"]);
                Scms scms = Mir.Analyze(((Dictionary<string, object>)itunesdic[track.TrackDatabaseID.ToString()])["Location"].ToString().Remove(0,17));
                if(scms != null)
                    db.AddTrack(track.TrackDatabaseID, scms);
                Console.WriteLine("Analysis of: " + ((Dictionary<string, object>)itunesdic[track.TrackDatabaseID.ToString()])["Location"] + " complete");
                
            }

            //Console.WriteLine(System.Environment.CurrentDirectory);

            //Scms scms = Mir.Analyze(@"C:\Users\Kevin\Music\01 Right Where I Belong.mp3");
            //Console.WriteLine(scms);
            //foreach (byte b in scms.ToBytes())
            //{
            //    Console.Write(b);
            //}
            //Console.ReadKey();
            //Db db = new Db();
            //db.AddTrack(1, scms);

            //Scms scms2 = db.GetTrack(1);
            //Console.WriteLine(scms2);
            //foreach (byte b in scms2.ToBytes())
            //{
            //    Console.Write(b);
            //}
            //Console.ReadKey();
            
        }
    }
}
